home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / LogicSim 3.0b Folder.sit / LogicSim 3.0b Folder / LogicSim 3.0b ƒ / LogicSim SDK 2.7 / LogicSimIntf.p < prev    next >
Text File  |  1995-09-18  |  10KB  |  493 lines

  1. unit LogicSimIntf;
  2.  
  3.                     { ** Interface for code ressource LogicSim modules   v2.7a ** }
  4.  
  5. interface
  6.  
  7. {$SETC INT_TIME := FALSE}
  8.  
  9.     uses
  10.         StdIntfs;
  11.  
  12.     const
  13.         kStimCmdMaxLen = 8;
  14.  
  15.     type
  16.         PinNumT = Integer;
  17.         GateNumT = Integer;
  18.         NodeNumT = Integer; {not used in component def proc}
  19.  
  20.     type
  21.         PinKindT = Integer;
  22.         ExtPinFlagT = Integer;
  23.         DelayModeT = Integer;
  24.  
  25.     type
  26.         PixelT = Integer;
  27.         TickT = Longint;
  28.         PicDirectionT = Integer;
  29.  
  30.     type
  31.         LSProcPtr = ProcPtr;
  32.         LSMessageT = Longint;
  33.         LSVarCodeT = Longint;
  34.  
  35.     type
  36.         ClassNameT = Str63;        {too long! should have been Str32}
  37.         ClassIDT = record
  38.                 name: ClassNameT;
  39.             end;
  40.         PinNameT = Str63;
  41.         ComponentNameT = Str63;
  42.         LongClassNameT = Str255;
  43.         FamilyNameT = Str32;        {= family file name}
  44.         StimCmdT = string[kStimCmdMaxLen];
  45.  
  46.     type
  47.         SValue = Integer;
  48.         {$IFC INT_TIME}
  49.         STime = Longint;
  50.         {$ELSEC}
  51.         STime = Extended;
  52.         {$ENDC}
  53.  
  54.     const    {ExtPinFlagT}
  55.         kExtInput = 1;
  56.         kExtOutput = 2;
  57.         kExtInOut = 3;
  58.  
  59.     const    {PinKindT}
  60.         kInputPin = 1;
  61.         kOutputPin = 2;
  62.         kInOutPin = 3;
  63.  
  64.     const    {PinNumT}
  65.         kAllPins = -1; {for simulation message}
  66.  
  67.     const    {STime}
  68.         {$IFC INT_TIME}
  69.         INF_TIME = $7FFFFFFF;
  70.         {$ELSEC}
  71.         INF_TIME = 1.0e20; { INF doesn't work with CW if used as const, why ?}
  72.         {$ENDC}
  73.  
  74.     const    {SValue}
  75.         L0 = 0;
  76.         L1 = 1;
  77.         LX = -1; {unknown}
  78.         LZ = -2; {hight impedance}
  79.  
  80.     const    {DelayModeT}
  81.         simulMin = 1;
  82.         simulMax = 2;
  83.         simulMean = 3;
  84.         simulRandom = 4;
  85.  
  86.                     {Class messages}
  87.  
  88.     const {LSMessageT}
  89.         msgNewClass = 1;
  90.         msgDisposeClass = 2;
  91.  
  92.     type
  93.         PrmClassRec = record
  94.                 image: PicHandle;
  95.                 name: LongClassNameT;
  96.                 id: ClassIDT;
  97.                 fileSpec: FSSpec;                                 {reserved}
  98.                 becomeExtPin: ExtPinFlagT;
  99.                 titleOffset: PixelT;                            {LS v2.6a2}
  100.                 resultCode: OSErr;                                {LS v2.6a2}
  101.             end;
  102.         PrmClassPtr = ^PrmClassRec;
  103.  
  104.  
  105.                 {Symbol messages}
  106.  
  107.     const
  108.         msgNewSymbol = 10;
  109.         msgDisposeSymbol = 11;
  110.         msgSimClick = 12;
  111.         msgDrawSymbol = 13;
  112.         msgOptionDialog = 14;
  113.         msgSymGetCharacs = 15;{  (it was msgCanOptionDialog in older version), used to get the fields "can(something)" }
  114.         msgSetSymbolParams = 16;
  115.         msgGetSymbolParams = 17;
  116.  
  117.     type
  118.         PrmSymbolRec = record
  119.                 frame: Rect;
  120.                 modifiers: Integer;
  121.                 canOptionDialog: Boolean;
  122.                 paramsStorage: Handle;
  123.                 optionDialogResult: Boolean;
  124.                 canRotation: Boolean;                            {LS 2.6.2a}
  125.                 rotDirection: PicDirectionT;                             {LS 2.6.2a}
  126.             end;
  127.         PrmSymbolPtr = ^PrmSymbolRec;
  128.  
  129.  
  130.             {Gate messages}
  131.  
  132.     const {LSMessageT}
  133.         msgNewGate = 20;
  134.         msgDisposeGate = 21;
  135.         msgReset = 22;
  136.         msgSimulation = 23;
  137.         msgTimer = 24;
  138.         msgGetGateParams = 26;
  139.         msgStimuli = 27;
  140.  
  141.  
  142.     type
  143.         timerIDT = Longint;
  144.  
  145.         PrmGateRec = record
  146.                 pinUpdated: PinNumT;
  147.                 paramsStorage: Handle;
  148.                 success: Boolean;
  149.                 timerID: TimerIDT;
  150.                 stimCmd: StringPtr;                    {LS 2.6a}
  151.                 stimCmdHandled: Boolean;            {LS 2.6a}
  152.             end;
  153.         PrmGatePtr = ^PrmGateRec;
  154.  
  155.  
  156.     type
  157.         LSEnvRec = record
  158.                 setOutputProc: ProcPtr;
  159.                 getInputProc: ProcPtr;
  160.                 reserved: ProcPtr;
  161.                 declarePinProc: ProcPtr;
  162.                 forceGateSimProc: ProcPtr;
  163.                 invalSymbolProc: ProcPtr;
  164.                 loopProc: ProcPtr;
  165.                 addTimerProc: ProcPtr;
  166.                 printMsgProc: ProcPtr;
  167.                 setOutputInitialValueProc: ProcPtr;
  168.                 {and other data ...}
  169.             end;
  170.         LSEnvPtr = ^LSEnvRec;
  171.  
  172.  
  173.         ClassRefT = ^Char;
  174.         SymbolRefT = ^Integer;
  175.         GateRefT = ^Longint;
  176.  
  177.         LSParamPtr = record
  178.                 case Integer of
  179.                     0: (
  180.                             prmClass: PrmClassPtr;
  181.                     );
  182.                     1: (
  183.                             prmSymbol: PrmSymbolPtr;
  184.                     );
  185.                     2: (
  186.                             prmGate: PrmGatePtr;
  187.                     );
  188.             end;
  189.  
  190.         LSBlock = record
  191.                 varCode: LSVarCodeT;
  192.                 msg: LSMessageT;
  193.                 prm: LSParamPtr;
  194.                 classRef: ClassRefT;
  195.                 symbolRef: SymbolRefT;
  196.                 gateRef: GateRefT;
  197.                 classData: Handle;
  198.                 symbolData: Handle;
  199.                 gateData: Handle;
  200.                 env: LSEnvPtr;
  201.                 reserved: Longint;
  202.             end;
  203.  
  204.  
  205.                     { delays }
  206.  
  207.     type
  208.         MDelaysRec = record
  209.                 min: STime;
  210.                 max: STime;
  211.                 mean: STime;
  212.             end;
  213.         DelaysPtr = ^MDelaysRec;
  214.  
  215.         RFDelaysRec = record
  216.                 rise: MDelaysRec;
  217.                 fall: MDelaysRec;
  218.             end;
  219.  
  220.         DelaySpec = record
  221.                 dsFamilyName: FamilyNameT;
  222.                 dsDelays: RFDelaysRec;
  223.             end;
  224.  
  225.  
  226.     procedure CallComponentDefProc (blk: LSBlock;
  227.                                     proc: LSProcPtr);
  228.     inline
  229.         $205F, $4E90;
  230.  
  231.  
  232.     procedure LSDeclarePin (env: LSEnvPtr;
  233.                                     classRef: ClassRefT;
  234.                                     loc: Point;
  235.                                     kind: PinKindT;
  236.                                     delays: DelaysPtr;
  237.                                     name: PinNameT);
  238.     procedure LSGetInput (env: LSEnvPtr;
  239.                                     gateRef: GateRefT;
  240.                                     pinN: PinNumT;
  241.                                     var value: SValue);
  242.     procedure LSSetOutput (env: LSEnvPtr;
  243.                                     gateRef: GateRefT;
  244.                                     pinN: PinNumT;
  245.                                     value: SValue);
  246.     procedure LSSetOutputInitialValue (env: LSEnvPtr;
  247.                                     gateRef: GateRefT;
  248.                                     pinN: PinNumT;
  249.                                     value: SValue);
  250.     procedure LSForceGateSim (env: LSEnvPtr;
  251.                                     gateRef: GateRefT);
  252.     procedure LSInvalSymbol (env: LSEnvPtr;
  253.                                     symbolRef: SymbolRefT);
  254.     procedure LSAddTimer (env: LSEnvPtr;
  255.                                     gateRef: GateRefT;
  256.                                     date: STime);
  257.     procedure LSLoop (env: LSEnvPtr;
  258.                                     symbolRef: SymbolRefT);
  259.     function LSStimNewValueCmd (env: LSEnvPtr;
  260.                                     cmd: StringPtr;
  261.                                     var v: SValue): Boolean;
  262.     procedure LSPrintMsg (env: LSEnvPtr;
  263.                                     symOrGate: univ Ptr;
  264.                                     theMessage: Str255);
  265.  
  266.     function GetPoint (h, v: Integer): Point;
  267.     function CompareClassID (id1, id2: ClassIDT): Boolean;
  268.     procedure SetClassID (var id: ClassIDT;
  269.                                     s: ClassNameT);
  270.     function LogicAND (a, b: SValue): SValue;
  271.     function LogicOR (a, b: SValue): SValue;
  272.     function LogicNOT (a: SValue): SValue;
  273.     function PositiveEdge (oldV, newV: SValue): Boolean;
  274.     function NegativeEdge (oldV, newV: SValue): Boolean;
  275.  
  276. implementation
  277.  
  278.     function CompareClassID (id1, id2: ClassIDT): Boolean;
  279.     begin
  280.         CompareClassID := (id1.name = id2.name);
  281.     end;
  282.  
  283.     procedure SetClassID (var id: ClassIDT;
  284.                                     s: ClassNameT);
  285.     begin
  286.         id.name := s;
  287.     end;
  288.  
  289.     function GetPoint (h, v: Integer): Point;
  290.         var
  291.             p: Point;
  292.     begin
  293.         p.h := h;
  294.         p.v := v;
  295.         GetPoint := p;
  296.     end;
  297.  
  298.     function LogicAND (a, b: SValue): SValue;
  299.         var
  300.             result: SValue;
  301.     begin
  302.         if (a = L1) & (b = L1) then
  303.             result := L1
  304.         else if (a = L0) | (b = L0) then
  305.             result := L0
  306.         else
  307.             result := LX;
  308.         LogicAND := result;
  309.     end;
  310.  
  311.     function LogicOR (a, b: SValue): SValue;
  312.         var
  313.             result: SValue;
  314.     begin
  315.         if (a = L1) | (b = L1) then
  316.             result := L1
  317.         else if (a = L0) & (b = L0) then
  318.             result := L0
  319.         else
  320.             result := LX;
  321.         LogicOR := result;
  322.     end;
  323.  
  324.     function LogicNOT (a: SValue): SValue;
  325.         var
  326.             result: SValue;
  327.     begin
  328.         if a = L0 then
  329.             result := L1
  330.         else if a = L1 then
  331.             result := L0
  332.         else
  333.             result := LX;
  334.         LogicNOT := result;
  335.     end;
  336.  
  337.     function PositiveEdge (oldV, newV: SValue): Boolean;
  338.     begin
  339.         PositiveEdge := ((newV = L1) & (oldV = L0));
  340.     end;
  341.  
  342.     function NegativeEdge (oldV, newV: SValue): Boolean;
  343.     begin
  344.         NegativeEdge := ((newV = L0) & (oldV = L1));
  345.     end;
  346.  
  347.     procedure Call_DeclarePin (classRef: ClassRefT;
  348.                                     loc: Point;
  349.                                     kind: PinKindT;
  350.                                     delays: DelaysPtr;
  351.                                     name: PinNameT;
  352.                                     proc: ProcPtr);
  353.     inline
  354.         $205F, $4E90;
  355.  
  356.     procedure LSDeclarePin (env: LSEnvPtr;
  357.                                     classRef: ClassRefT;
  358.                                     loc: Point;
  359.                                     kind: PinKindT;
  360.                                     delays: DelaysPtr;
  361.                                     name: PinNameT);
  362.     begin
  363.         Call_DeclarePin(classRef, loc, kind, delays, name, env^.declarePinProc);
  364.     end;
  365.  
  366.     procedure Call_SetOutput (gateRef: GateRefT;
  367.                                     pinN: PinNumT;
  368.                                     value: SValue;
  369.                                     proc: ProcPtr);
  370.     inline
  371.         $205F, $4E90;
  372.  
  373.     procedure LSSetOutput (env: LSEnvPtr;
  374.                                     gateRef: GateRefT;
  375.                                     pinN: PinNumT;
  376.                                     value: SValue);
  377.     begin
  378.         Call_SetOutput(gateRef, pinN, value, env^.setOutputProc);
  379.     end;
  380.  
  381.     procedure Call_SetOutputInitialValue (gateRef: GateRefT;
  382.                                     pinN: PinNumT;
  383.                                     value: SValue;
  384.                                     proc: ProcPtr);
  385.     inline
  386.         $205F, $4E90;
  387.  
  388.     procedure LSSetOutputInitialValue (env: LSEnvPtr;
  389.                                     gateRef: GateRefT;
  390.                                     pinN: PinNumT;
  391.                                     value: SValue);
  392.     begin
  393.         Call_SetOutputInitialValue(gateRef, pinN, value, env^.setOutputInitialValueProc);
  394.     end;
  395.  
  396.     procedure Call_GetInput (gateRef: GateRefT;
  397.                                     pinN: PinNumT;
  398.                                     var value: SValue;
  399.                                     proc: ProcPtr);
  400.     inline
  401.         $205F, $4E90;
  402.  
  403.     procedure LSGetInput (env: LSEnvPtr;
  404.                                     gateRef: GateRefT;
  405.                                     pinN: PinNumT;
  406.                                     var value: SValue);
  407.     begin
  408.         Call_GetInput(gateRef, pinN, value, env^.getInputProc);
  409.     end;
  410.  
  411.  
  412.     procedure Call_ForceGateSim (gateRef: GateRefT;
  413.                                     proc: ProcPtr);
  414.     inline
  415.         $205F, $4E90;
  416.  
  417.     procedure LSForceGateSim (env: LSEnvPtr;
  418.                                     gateRef: GateRefT);
  419.     begin
  420.         Call_ForceGateSim(gateRef, env^.ForceGateSimProc);
  421.     end;
  422.  
  423.  
  424.     procedure Call_InvalSymbol (symbolRef: SymbolRefT;
  425.                                     proc: ProcPtr);
  426.     inline
  427.         $205F, $4E90;
  428.  
  429.     procedure LSInvalSymbol (env: LSEnvPtr;
  430.                                     symbolRef: SymbolRefT);
  431.     begin
  432.         Call_InvalSymbol(symbolRef, env^.invalSymbolProc);
  433.     end;
  434.  
  435.     procedure Call_Loop (symbolRef: SymbolRefT;
  436.                                     proc: ProcPtr);
  437.     inline
  438.         $205F, $4E90;
  439.  
  440.     procedure LSLoop (env: LSEnvPtr;
  441.                                     symbolRef: SymbolRefT);
  442.     begin
  443.         Call_Loop(symbolRef, env^.loopProc);
  444.     end;
  445.  
  446.  
  447.     procedure Call_AddTimer (gateRef: GateRefT;
  448.                                     date: STime;
  449.                                     proc: ProcPtr);
  450.     inline
  451.         $205F, $4E90;
  452.  
  453.     procedure LSAddTimer (env: LSEnvPtr;
  454.                                     gateRef: GateRefT;
  455.                                     date: STime);
  456.     begin
  457.         Call_AddTimer(gateRef, date, env^.addTimerProc);
  458.     end;
  459.  
  460.     function LSStimNewValueCmd (env: LSEnvPtr;
  461.                                     cmd: StringPtr;
  462.                                     var v: SValue): Boolean;
  463.         var
  464.             result: Boolean;
  465.     begin
  466.         result := true;
  467.         if cmd^ = 'L0' then
  468.             v := L0
  469.         else if cmd^ = 'L1' then
  470.             v := L1
  471.         else if cmd^ = 'LX' then
  472.             v := LX
  473.         else if cmd^ = 'LZ' then
  474.             v := LZ
  475.         else
  476.             result := false;
  477.         LSStimNewValueCmd := result;
  478.     end;
  479.  
  480.     procedure Call_LSPrintMsg (symOrGate: univ Ptr;
  481.                                     theMessage: Str255;
  482.                                     proc: ProcPtr);
  483.     inline
  484.         $205F, $4E90;
  485.  
  486.     procedure LSPrintMsg (env: LSEnvPtr;
  487.                                     symOrGate: univ Ptr;
  488.                                     theMessage: Str255);
  489.     begin
  490.         Call_LSPrintMsg(symOrGate, theMessage, env^.printMsgProc);
  491.     end;
  492.  
  493. end.